﻿using HackApp.DataAccess;
using System;

namespace HackApp.BusinessLogic
{
	/// <summary>
	/// This is a container class for all business logic entities.
	/// This "master" class(not to be confused with something from which business logic classes are inherited from)
	/// will be a singleton(or static) for the sole purpose of using only one instance of
	/// Unit Of Work(in order to avoid optimistic concurrency errors hahahahaha) per http
	/// request(someone may also call this business request).
	/// This master class will be the only entity able to create all the business logic objects for the purpose of assigning
	/// them the same unit of work instance.
	/// </summary>
	public sealed class BusinessFactory //sealed in order to prevent inheritance of unitOfWork and multiple instances of it;
	{
    //private static BusinessFactory theOnlyInstance = null;

    internal static readonly IUnitOfWork unitOfWork = new UnitOfWork();

		public static BusinessLogicBaseClass GetBusinessObject(Type businessType)
		{
			BusinessLogicBaseClass inst = (BusinessLogicBaseClass)Activator.CreateInstance(businessType, true);
			inst.unitOfWork = unitOfWork;
			
			return inst;
		}
	}
}
